package com.mt.roll.wms.controller;

import com.mt.roll.core.base.BaseController;
import com.mt.roll.core.constants.CommonConstant;
import com.mt.roll.core.params.IdParam;
import com.mt.roll.core.validator.groups.AddGroup;
import com.mt.roll.core.validator.groups.PageGroup;
import com.mt.roll.core.validator.groups.UpdateGroup;
import com.mt.roll.core.vo.IdVo;
import com.mt.roll.core.vo.PageVo;
import com.mt.roll.core.vo.R;
import com.mt.roll.wms.params.*;

import com.mt.roll.wms.service.AreaLocationService;
import com.mt.roll.wms.service.AreaService;
import com.mt.roll.wms.service.AreaShelfService;
import com.mt.roll.wms.vo.AreaLocationVo;
import com.mt.roll.wms.vo.AreaShelfVo;
import com.mt.roll.wms.vo.AreaVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.groups.Default;

/**
 * @auther yanyang
 * @date 2021/10/15 10:08
 */

@RestController
@RequestMapping(CommonConstant.API_MODULE_WMS + "area")
@Slf4j
@Api(value = "缓存区信息", tags = "缓存区信息", hidden = false)

public class AreaController extends BaseController {

    @Autowired
    private AreaService areaService;

    @PostMapping(value = "page")
    @ApiOperation(value = "查看缓存区信息")
    private R<PageVo<AreaVo>> area(@Validated({PageGroup.class, Default.class}) @RequestBody AreaQueryParam areaQueryParam){
        return areaService.area(areaQueryParam);
    }

    @PostMapping(value = "getById")
    @ApiOperation(value = "获取缓存区信息")
    private R<AreaVo> areaById(@Validated @RequestBody IdParam idParam) {
        return areaService.areaById(idParam);
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增缓存区")
    private R<IdVo> add(@Validated({AddGroup.class, Default.class}) @RequestBody AreaParam areaParam) {
        return areaService.add(areaParam);
    }

    @PostMapping(value = "update")
    @ApiOperation(value = "更新缓存区")
    private R<IdVo> update(@Validated({UpdateGroup.class, Default.class}) @RequestBody AreaParam areaParam) {
        return areaService.update(areaParam);
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除缓存区")
    private R<IdVo> delete(@Validated @RequestBody IdParam idParam) {
        return areaService.delete(idParam);
    }



    @Autowired
    private AreaShelfService areaShelfService;

    @PostMapping(value="shelf")
    @ApiOperation(value = "查看货架")
    private R<PageVo<AreaShelfVo>> shelf(@Validated({PageGroup.class, Default.class}) @RequestBody AreaShelfQueryParam areaShelfQueryParam){
        return areaShelfService.shelf(areaShelfQueryParam);
    }

    @PostMapping(value="shelfById")
    @ApiOperation(value = "查看货架")
    private R<AreaShelfVo> shelfById(@Validated @RequestBody IdParam idParam) {
        return areaShelfService.shelfById(idParam);
    }

    @PostMapping(value = "addshelf")
    @ApiOperation(value = "新增货架")
    private R<IdVo> addShelf(@Validated({AddGroup.class, Default.class}) @RequestBody AreaShelfParam areaShelfParam) {
        return areaShelfService.addShelf(areaShelfParam);
    }

    @PostMapping(value = "updateshelf")
    @ApiOperation(value = "更新货架")
    private R<IdVo> updateShelf(@Validated({UpdateGroup.class, Default.class}) @RequestBody AreaShelfParam areaShelfParam) {
        return areaShelfService.updateShelf(areaShelfParam);
    }

    @PostMapping(value = "deleteshelf")
    @ApiOperation(value = "删除货架")
    private R<IdVo> deleteShelf(@Validated @RequestBody IdParam idParam) {
        return areaShelfService.deleteShelf(idParam);
    }



    @Autowired
    private AreaLocationService areaLocationService;

    @PostMapping(value="locationByShelf")
    @ApiOperation(value = "查看库位")
    private R<PageVo<AreaLocationVo>> locationByShelf(@Validated({PageGroup.class, Default.class}) @RequestBody AreaShelfQueryParam areaShelfQueryParam){
        return areaLocationService.locationByShelf(areaShelfQueryParam);
    }

    @PostMapping(value="locationById")
    @ApiOperation(value = "库位详情")
    private R<AreaLocationVo> locationById(@Validated @RequestBody IdParam idParam) {
        return areaLocationService.locationById(idParam);
    }

    @PostMapping(value="addlocation")
    @ApiOperation(value = "添加库位")
    private R<IdVo> addLocation(@Validated({AddGroup.class, Default.class}) @RequestBody AreaLocationParam areaLocationParam) {
        return areaLocationService.addLocation(areaLocationParam);
    }

    @PostMapping(value = "updatelocation")
    @ApiOperation(value = "更新库位")
    private R<IdVo> updateLocation(@Validated({UpdateGroup.class, Default.class}) @RequestBody AreaLocationParam areaLocationParam) {
        return areaLocationService.updateLocation(areaLocationParam);
    }

    @PostMapping(value = "deletelocation")
    @ApiOperation(value = "删除库位")
    private R<IdVo> deleteLocation(@Validated @RequestBody IdParam idParam) {
        return areaLocationService.deleteLocation(idParam);
    }

    @PostMapping(value = "getCode")
    @ApiOperation(value = "获取code")
    private R<String> getCode() {
        return areaService.getCode();
    }

}